package com.inspur.gs.sbssdl.sbyxgl.djjl.djjl.front.newdjpzxz_frm.voactions;
import com.inspur.edp.bef.api.lcp.ILcpFactory;
import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bef.engine.entity.AssociationInfo;
import com.inspur.edp.bff.spi.*;
import com.inspur.edp.bef.api.action.*;
import com.inspur.edp.bef.api.services.IBefSessionManager;
import com.inspur.edp.cef.entity.changeset.ModifyChangeDetail;
import com.inspur.edp.cef.entity.entity.IEntityData;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class xzdatasVOAction extends AbstractFSAction<VoidActionResult> {

	private String[] ids;
	private String[] dataIds;
	public xzdatasVOAction(String[] ids, String[] dataIds) {
		this.ids = ids;
		this.dataIds = dataIds;
	}
	@Override
	public void execute() {
		SpringBeanUtils.getBean(IBefSessionManager.class).createSession();
		try {
			//点检配置变更
			ILcpFactory iLcpFactory = SpringBeanUtils.getBean(ILcpFactory.class);
			String djid = "efd56b39-0e8d-4441-9fa1-2b019b6fd862";// 设备台账id
			IStandardLcp djlcp = iLcpFactory.createLcpByBEId(djid);

			for (String id : ids) {
				// 主表变更
				ModifyChangeDetail change = new ModifyChangeDetail(id);
				change.getPropertyChanges().put("gjp",true);
				ArrayList<String> nodeCodes = new ArrayList<>();
				nodeCodes.add("djbz");
				ArrayList<String> hierarchyIds = new ArrayList<>();
				hierarchyIds.add(id);
				for (String dataId : dataIds) {
					IEntityData djmx = djlcp.retrieveDefaultChild(nodeCodes, hierarchyIds);
					ModifyChangeDetail childChange = new ModifyChangeDetail(djmx.getID());
					AssociationInfo djpzInfo = new AssociationInfo();
					djpzInfo.setValue("djbz",dataId);
					childChange.getPropertyChanges().put("djbz", djpzInfo);
					change.addChildChangeSet("djbz", childChange);
				}
				djlcp.modify(change);
			}
			djlcp.save();
		} finally {
			SpringBeanUtils.getBean(IBefSessionManager.class).closeCurrentSession();
		}
	}
}
